/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						     high_scores.h

	$Header: /game/high_scores.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( HIGH_SCORES_H_INCLUDED )
#define HIGH_SCORES_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <bitset>
#include <iosfwd>
#include "counted_ptr.h"
#include "creature_type.h"
#include "handler.h"
#include "sized_int_types.h"

class t_adventure_map;
class t_high_scores;
class t_high_score_entry;

typedef t_counted_ptr< t_high_scores > t_high_scores_ptr;


// ------------------------------------------------------------------------------
// high score table entry
// ------------------------------------------------------------------------------
class t_high_score_entry : public t_counted_object
{
public:
	t_high_score_entry();
	explicit t_high_score_entry( t_high_score_entry const & entry );
	t_high_score_entry( std::string const & days, 
						std::string const & map_name,
						std::string const & player_name,
						t_creature_type		portrait_type,
						std::string const & score );
	
	std::string const &		get_days() const;
	std::string const &		get_map_name() const;
	std::string const &		get_player_name() const;
	t_creature_type			get_portrait_type() const;
	std::string const &		get_score() const;
	bool					is_highlighted() const;
	void					set( std::string const & days, 
								 std::string const & map_name,
								 std::string const & player_name,
								 t_creature_type	 portrait_type,
								 std::string const & score );
	void					set_days( std::string const & );
	void					set_highlighted( bool highlighted );
	void					set_map_name( std::string const & );
	void					set_player_name( std::string const & );
	void					set_portrait_type( t_creature_type );
	void					set_score( std::string const & );



private:
	std::string				m_days;
	std::string				m_map_name;
	std::string				m_player_name;
	t_creature_type			m_portrait_type;
	std::string				m_score;
	bool					m_highlighted;
};

// ------------------------------------------------------------------------------
// inline t_high_score_entry methods
// ------------------------------------------------------------------------------

inline t_high_score_entry::t_high_score_entry() :
	m_portrait_type( k_creature_none ),
	m_highlighted( false )
{
}

inline t_high_score_entry::t_high_score_entry( t_high_score_entry const & entry )
{
	m_days = entry.get_days();
	m_map_name = entry.get_map_name();
	m_player_name = entry.get_player_name();
	m_portrait_type = entry.get_portrait_type();
	m_score = entry.get_score();
	m_highlighted = entry.is_highlighted();
}

inline bool t_high_score_entry::is_highlighted() const
{
	return m_highlighted;
}

inline void t_high_score_entry::set_highlighted( bool highlighted )
{
	m_highlighted = highlighted;
}

// ------------------------------------------------------------------------------
// high scores class
// ------------------------------------------------------------------------------
class t_high_scores	: public t_counted_object
{
public:
	t_high_scores();

	void							build_default_scores_table();
	bool							check_high_scores(	std::string const &		title,
														int						days,
														int						final_score, 
														std::string	 const &	player_name,
														bool					is_standard,
														t_creature_type			portrait_type = k_creature_none );
	t_high_score_entry *			get_campaign_entry( int ndx );
	t_high_score_entry *			get_standard_entry( int ndx );
	void							set_campaign_entry( int ndx,
														std::string const & days, 
														std::string const & map_name,
														std::string const & player_name,
														t_creature_type		portrait_type,
														std::string const & score );
	void							set_standard_entry( int ndx,
														std::string const & days, 
														std::string const & map_name,
														std::string const & player_name,
														t_creature_type		portrait_type,
														std::string const & score );

	bool read( std::streambuf & stream );
	bool write( std::streambuf & stream ) const;

	enum { k_num_score_entries = 10 };

private:
	t_high_score_entry	m_standard_scores[k_num_score_entries];
	t_high_score_entry	m_campaign_scores[k_num_score_entries];
};

// ------------------------------------------------------------------------------
// global read/write score functions
// ------------------------------------------------------------------------------
t_high_scores_ptr	read_high_scores_file();
bool				write_high_scores_file( t_high_scores_ptr const high_scores );


#endif // !defined( HIGH_SCORES_H_INCLUDED )
